package com.huawei.leetcode;

import java.util.HashMap;
import java.util.Map;

public class Code141 {
    private class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
            next = null;
        }
    }

    public boolean hasCycle(ListNode head) {
        ListNode index = head;
        Map<ListNode,Integer> table = new HashMap<>();
        while(true){
            if(index == null){
                break;
            }
            if(table.containsKey(index)){
                return true;
            }else {
                table.put(index,0);
                index = index.next;
            }
        }
        return false;
    }
}
